package web

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"jk-webook/internal/service/auth2/wechat"
	"net/http"
)

type OAuth2WechatHandler struct {
	svc wechat.Service
}

func (h *OAuth2WechatHandler) RegisterRoutes(server *gin.Engine) {
	g := server.Group("/auth2/wechat")
	g.GET("/authUrl", h.AuthURL)
	g.Any("/callback", h.Callback)
}

func (h *OAuth2WechatHandler) AuthURL(context *gin.Context) {

}

func (h *OAuth2WechatHandler) Callback(ctx *gin.Context) {
	code := ctx.Query("code")
	state := ctx.Query("state")
	verifyCode, err := h.svc.VerifyCode(ctx, code, state)
	if err != nil {
		ctx.JSON(http.StatusOK, wechat.Result{ErrCode: 5})
	}
	//设置登录的token
	fmt.Println(verifyCode)
}
